//
//  CustomView.m
//  Custom
//
//  Created by apple on 15/9/12.
//  Copyright (c) 2015年 戴维营. All rights reserved.
//

#import "CustomView.h"

@implementation CustomView

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame])
    {
        CGSize size = frame.size;
        
        _aLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0,size.width, size.height * 0.8)];
        
        //字体的颜色
        _aLabel.textColor = [UIColor redColor];
        
        //文字对齐方式
        _aLabel.textAlignment = NSTextAlignmentCenter;
        
        //字体的大小
        _aLabel.font = [UIFont boldSystemFontOfSize:25];
        
        [self addSubview:_aLabel];
        
        
        _bLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, size.height * 0.8, size.width, size.height * 0.2)];
        
        _bLabel.textAlignment = NSTextAlignmentCenter;
        
        _bLabel.textColor = [UIColor orangeColor];
        
        _bLabel.font = [UIFont boldSystemFontOfSize:13];
        
        [self addSubview:_bLabel];

    }
    
    return self;
}


- (void)layoutSubviews
{
    [super layoutSubviews];
    
//    获取当前视图的大小；
    CGSize size = self.frame.size;
    
    _aLabel.frame = CGRectMake(0, 0, size.width, size.height * 0.8);
    
    _bLabel.frame = CGRectMake(0, size.height * 0.8, size.width, size.height * 0.2);
}


- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    
#if 0
//   --->BLOCK

    //判断block是否存在
    
    if (_touchDown)
    {
        _touchDown(self);
    }
    
    if (_changeColor)
    {
        //传递数据
        
        _aLabel.backgroundColor = _changeColor(self);
    }
    
#endif
    
    //判断_delegate所指向的对象是否实现了touchdown：index：方法
    
    if (_delegate && [_delegate respondsToSelector:@selector(touchDown:index:)])
    {
        [_delegate touchDown:self index:23];
    }
    
    if (_delegate &&[_delegate respondsToSelector:@selector(changeColor)])
    {
        _aLabel.backgroundColor = [_delegate changeColor];
    }
}

@end
